package com.example.homecunter.video;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.example.common.utils.BaseEntity;
import com.example.common.utils.OnItemClickListener;
import com.example.homecunter.R;
import com.example.homecunter.news.adapter.NewsPagerAdapter;
import com.example.homecunter.news.newsentity.NewsType;
import com.example.homecunter.video.adapter.ChannelAdapter;
import com.example.homecunter.video.adapter.VideoAdapter;
import com.example.homecunter.video.adapter.VideoTypePagerAdapter;
import com.example.homecunter.video.entity.ChannelEntity;
import com.example.homecunter.video.entity.VideoEntity;
import com.example.homecunter.video.viewmodel.ChannelViewModel;
import com.example.mvvmcore.fragment.BaseMVVMFragment;
import com.google.android.material.tabs.TabLayout;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;


public class GsyvFragment extends BaseMVVMFragment<ChannelViewModel> {

    View view;
    private EditText etSeek;
    private TabLayout gsyvTab;
    private ViewPager gsyvVp;


    @Override
    protected void initEnv() {
//        dataSource.setValue(new ChannelEntity());
    }

    @Override
    protected void initData() {


    }

    @Override
    protected Class getViewModelClazz() {
        return ChannelViewModel.class;
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_gsyv;
    }

    @Override
    protected void preparVarMap(Map<Integer, Object> map) {
//        map.put(BR.own, this);
    }

    @Override
    protected void stopLoad() {

    }

    @Override
    protected void lazyLoad() {
        Log.i("--b", "lazyLoad: GsyvFragment");
        mViewModel.channel().observe(getActivity(), new Observer<BaseEntity<List<ChannelEntity>>>() {
            @Override
            public void onChanged(BaseEntity<List<ChannelEntity>> listBaseEntity) {
                List<ChannelEntity> data1 = listBaseEntity.getData();
                VideoTypePagerAdapter videoTypePagerAdapter = new VideoTypePagerAdapter(getActivity().getSupportFragmentManager(), data1);

                gsyvVp.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(gsyvTab));
                gsyvVp.setAdapter(videoTypePagerAdapter);
                gsyvTab.setupWithViewPager(gsyvVp);

            }
        });
    }


    @Nullable
    @org.jetbrains.annotations.Nullable
    @Override
    public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        view = super.onCreateView(inflater, container, savedInstanceState);
        initView();
        return view;
    }

    private void initView() {
        etSeek = (EditText) view.findViewById(R.id.et_seek);
        gsyvTab = (TabLayout) view.findViewById(R.id.gsyv_tab);
        gsyvVp = (ViewPager) view.findViewById(R.id.gsyv_vp);
    }
}